/**
 * 
 */
package trungsi.gea.photos.stripes;

import java.util.Locale;

import javax.servlet.ServletContext;

import net.sourceforge.stripes.config.Configuration;
import net.sourceforge.stripes.integration.spring.SpringHelper;
import net.sourceforge.stripes.validation.DefaultTypeConverterFactory;
import net.sourceforge.stripes.validation.TypeConverter;
import trungsi.gea.photos.domain.Folder;
import trungsi.gea.photos.domain.Photo;

/**
 * @author trungsi
 *
 */
public class CustomTypeConverterFactory extends DefaultTypeConverterFactory {
	
	@Override
	@SuppressWarnings("unchecked")
	public TypeConverter getInstance(Class<? extends TypeConverter> clazz,
			Locale locale) throws Exception {
		TypeConverter tc = super.getInstance(clazz, locale);
		ServletContext sc = getConfiguration().getServletContext();
		
		SpringHelper.injectBeans(tc, sc);
		
		return tc;
	}
	
	@Override
	public void init(Configuration configuration) {
		super.init(configuration);
		
		add(Photo.class, EntityTypeConverter.class);
		add(Folder.class, EntityTypeConverter.class);
		add(java.util.Date.class, DateTypeConverter.class);
	}

}
